package com.ctfo.ulcp.exp.db

import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.selectAll

data class User(val id: Int, val name: String, val age: Int?)

object Users : Table("t_user") {
    val id = integer("ID").autoIncrement()
    val name = varchar("NAME", length = 50)
    val age = integer("AGE")

    override val primaryKey = PrimaryKey(id)

    suspend fun find(id: Int): User? {
        return DSL.dbQuery {
            val t0 = System.currentTimeMillis()
            val r = Users.selectAll().where { Users.id eq id }
                .map { User(it[Users.id], it[name], it[age]) }
                .singleOrNull()
            println("query_time :${System.currentTimeMillis() - t0}")
            r
        }
    }

}